;=================================================================================
;=========== SOME FUNCTION FOR PLANE 3D
;=================================================================================
Structure iPLANE
 		; Normal vector of the plane.
		Normal.iVECTOR3
		; Distance from origin.
		D.f
EndStructure

Macro PLANE_(dest,  dd, nx, ny, nz)
  dest\Normal\x = nx
  dest\Normal\y = ny
  dest\Normal\z = nz
  dest\D = dd
EndMacro

Procedure Plane_getMemberPoint(*vec.iVECTOR3, *plan.iPLANE)
	 *vec\x = *plan\Normal\x * ( - *plan\D)
	 *vec\y = *plan\Normal\y * ( - *plan\D)
	 *vec\z = *plan\Normal\z * ( - *plan\D)
EndProcedure		

Procedure Plane_recalculateD(*plane.iPLANE, *MPoint.iVECTOR3)
		; Recalculates the distance from origin by applying a new member point To the plane.
		*plane\D = - Vec3_DotProduct(*MPoint, @*plane\Normal)
EndProcedure	

Procedure Plane_setPlane(*plane.iPLANE, *p1.iVECTOR3,  *n.iVECTOR3)
	*plane\Normal\x = *n\x
  *plane\Normal\y = *n\y
  *plane\Normal\z = *n\z
  Plane_recalculateD(*plan, *p1)
EndProcedure		

Procedure.f Plane_getDistance(*plane.iPLANE, *p1.iVECTOR3)
    Protected dd.f 
    dd = Vec3_DotProduct(*p1, @*plane\Normal) + *plane\D
    ProcedureReturn dd
EndProcedure



; IDE Options = PureBasic 4.30 Beta 5 (Windows - x86)
; CursorPosition = 35
; Folding = -